package cn.com.gas.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;

import cn.com.common.result.DataResult;
import cn.com.gas.entity.GasForewarningZeroEntity;
import cn.com.gas.service.GasForewarningZeroService;
import cn.com.system.entity.SysDept;
import cn.com.system.service.DeptService;
import cn.com.util.TsBqUtils;

/**
 * 零数据异常预警
 *
 * @author shaochangyang
 * @email l2l84o7o5@live.com
 * @date 2024-12-05 22:23:53
 */
@RestController
@RequestMapping("/gas/forewarningZero")
public class GasForewarningZeroController {
	@Autowired
	private GasForewarningZeroService gasForewarningZeroService;

	@Autowired
	private DeptService deptService;

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@ApiOperation(value = "查询分页数据")
	@PostMapping("/list")
	@ResponseBody
	public DataResult findListByPage(@RequestBody GasForewarningZeroEntity gasForewarningZero) {
		Page page = new Page(gasForewarningZero.getPage(), gasForewarningZero.getLimit());
		LambdaQueryWrapper<GasForewarningZeroEntity> queryWrapper = Wrappers.lambdaQuery();
		// 查询条件示例

		if (TsBqUtils.isNotNull(gasForewarningZero.getTaxorgcode())) {
			queryWrapper.eq(GasForewarningZeroEntity::getTaxorgcode, gasForewarningZero.getTaxorgcode());

		}

		if (!StringUtils.isEmpty(gasForewarningZero.getCreateTimeStart())) {

			queryWrapper.ge(GasForewarningZeroEntity::getCreateTime, gasForewarningZero.getCreateTimeStart().trim());

		}

		if (!StringUtils.isEmpty(gasForewarningZero.getCreateTimeEnd())) {

			queryWrapper.le(GasForewarningZeroEntity::getCreateTime, gasForewarningZero.getCreateTimeEnd().trim());

		}

		IPage<GasForewarningZeroEntity> iPage = gasForewarningZeroService.page(page, queryWrapper);
		
		List<GasForewarningZeroEntity> list = iPage.getRecords();
		
		for (GasForewarningZeroEntity gasForewarningZeroEntity : list) {
			String taxorgcode = gasForewarningZeroEntity.getTaxorgcode();
			SysDept dept = deptService.getById(taxorgcode);
			gasForewarningZeroEntity.setTaxorgcode(dept.getName());
		}
		
		return DataResult.success(iPage);
	}

}
